package com.es.www.kyl.controller.api;

import com.es.www.kyl.bean.R;
import com.es.www.kyl.bean.req.LoginReq;
import com.es.www.kyl.bean.req.WxLoginReq;
import com.es.www.kyl.bean.req.WxRefreshTokenReq;
import com.es.www.kyl.bean.req.client.UpdateUserReq;
import com.es.www.kyl.bean.res.LoginRes;
import com.es.www.kyl.bean.res.client.WxLoginRes;
import com.es.www.kyl.service.LoginService;
import com.es.www.kyl.service.SmsService;
import com.es.www.kyl.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;

/**
 * @author Estranger
 * @date 2025/7/31
 * description
 */
@Api(tags = "小程序登录模块")
@RequiredArgsConstructor
@RestController
@RequestMapping("/client/login")
public class ClientLoginController {

	private final LoginService loginService;
	private final UserService userService;



	/**
	 * 登录
	 * @return
	 */
	@ApiOperation("微信登录")
	@PostMapping("/wxLogin")
	public R<WxLoginRes> login(@RequestBody WxLoginReq loginReq) {
		return R.successResponse(loginService.wxLogin(loginReq));
	}


	/**
	 * 登录
	 * @return
	 */
	@ApiOperation("app登录")
	@PostMapping("/appLogin")
	public R<WxLoginRes> login(@RequestBody LoginReq loginReq) {
		return R.successResponse(loginService.appLogin(loginReq));
	}

	/**
	 * 刷新token
	 * @return
	 */
	@ApiOperation("刷新token")
	@PostMapping("/refreshToken")
	public R<LoginRes> refreshToken(@RequestBody @Validated WxRefreshTokenReq req) {
		return R.successResponse(loginService.refreshToken(req));
	}

	/**
	 * 退出登录
	 * @return
	 */
	@ApiOperation("退出登录")
	@PostMapping("/exitLogin")
	public R<Void> exitLogin(@RequestHeader("Authorization") @NotNull String accessToken) {
		loginService.exitLogin(accessToken);
		return R.successCommonResponse();
	}


	@ApiOperation("修改个人信息")
	@PostMapping("/updateUserInfo")
	public R<Void> updateUserInfo(@RequestBody @Validated UpdateUserReq req) {
		userService.updateUserInfo(req);
		return R.successCommonResponse();
	}

}
